package com.example.day03

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.example.day03.adapter.MyTab
import com.example.day03.adapter.SpAdapter
import com.example.day03.databinding.ActivityMainBinding
import com.example.day03.fg.FraFragment
import com.example.day03.fg.HomeFragment
import com.example.day03.fg.MsgFragment
import com.example.day03.fg.MyFragment
import com.example.day03.mvvm.BaseViewActivity
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener

class MainActivity : BaseViewActivity<ActivityMainBinding>(){
    lateinit var spAdapter: SpAdapter
    val list:ArrayList<Fragment> = arrayListOf()
    override fun bindLayoutId(): Int {
        return R.layout.activity_main
    }

    override fun initView() {
        list.add(HomeFragment())
        list.add(FraFragment())
        list.add(MsgFragment())
        list.add(MyFragment())
        spAdapter= SpAdapter(this,list)
        binding.vp2.adapter=spAdapter

        val list1:ArrayList<CustomTabEntity> = arrayListOf()
        list1.add(MyTab("首页",0,0))
        list1.add(MyTab("朋友",0,0))
        list1.add(MyTab("消息",0,0))
        list1.add(MyTab("我的",0,0))
        binding.tab.setTabData(list1)

        binding.tab.setOnTabSelectListener(object:OnTabSelectListener{
            override fun onTabSelect(position: Int) {
                binding.vp2.currentItem=position
            }

            override fun onTabReselect(position: Int) {

            }

        })
        binding.vp2.registerOnPageChangeCallback(object:OnPageChangeCallback(){
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.tab.currentTab=position
            }
        })
    }

    override fun initDate() {

    }

}